//
//  ViewController.m
//  TransitionAnimation
//
//  Created by tgs on 2017/6/26.
//  Copyright © 2017年 tgs. All rights reserved.
//

#import "ViewController.h"
#import "TwoViewController.h"
#import "TransitionObj.h"
#import "TwoCollectionViewCell.h"
#import "ThreeViewController.h"

static NSString * const reuseIdentifier = @"Cell";

@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self stepUI];
}

- (void)stepUI{
    
    UIButton *btnClickMe = [[UIButton alloc] initWithFrame:CGRectMake(50, 80, 120, 30)];
    [btnClickMe setTitle:@"点我Present" forState:UIControlStateNormal];
    [btnClickMe setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:btnClickMe];
     [btnClickMe addTarget:self action:@selector(present) forControlEvents:UIControlEventTouchUpInside];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(150, 180);
    layout.minimumInteritemSpacing = 10;
    layout.minimumLineSpacing = 10;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 114, self.view.bounds.size.width, self.view.bounds.size.height-114) collectionViewLayout:layout];
    [self.collectionView registerNib:[UINib nibWithNibName:@"TwoCollectionViewCell" bundle:nil]  forCellWithReuseIdentifier:reuseIdentifier];
    [self.view addSubview:self.collectionView];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    
}

- (void)present{
    TwoViewController *presentedVC = [TwoViewController new];
//    presentedVC.delegate = self;
    [self presentViewController:presentedVC animated:YES completion:nil];
}

#pragma mark <UICollectionViewDataSource>
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 20;
}

- (TwoCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    TwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    _currentIndexPath = indexPath;
     ThreeViewController  *vc = [[ThreeViewController alloc] init];
    //设置导航控制器的代理为推出的控制器，可以达到自定义不同控制器的退出效果的目的
    self.navigationController.delegate = vc;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
